﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MySpiderMgr.Data.EF
{
    public class EFRepository<T> : IRepository<T> where T : class
    {
        protected MyDbContext _db = null;

        public EFRepository()
        {
            this._db = new MyDbContext();
        }
        public EFRepository(MyDbContext SqlDbContext)
        {
            this._db = SqlDbContext;
        }
        public void Add(T Entity)
        {
            _db.Add(Entity);
        }
        public void Delete(T Entity)
        {
            _db.Remove(Entity);
        }
        public T GetById<V>(V Id)
        {
            return _db.Find<T>(Id);
        }
        public void Update(T Entity)
        {
            _db.Update(Entity);
        }

        protected IQueryable<T> TableNoTracking
        {
            get
            {
                return _db.Set<T>().AsNoTracking();
            }
        }
        protected IQueryable<T> Table
        {
            get
            {
                return _db.Set<T>().AsTracking();
            }
        }

    }
}
